<%layout("/eova/layout/default.html",{'title' : 'Dialog' }){%>

<form id="myForm" method="post" class="form" style="padding: 5px;">
        <table class="table" style="width: 100%;">
            <tr>
                <th>所属菜单编码</th>
                <td>
                    <#text id="menu_code" name="menu_code" value="${menuCode}" isReadonly="true" />
                </td>
            </tr>
            <tr>
                <th style="width:110px;">图标</th>
                <td>
                    <#icon id="icon" name="icon" value="eova-icon0" /> (人靠衣装马靠鞍，选个图标高大上)
                </td>
            </tr>
            <tr>
                <th>名称</th>
                <td>
                    <#text id="name" name="name" value="" /> (必填)
                </td>
            </tr>
            <tr>
                <th>前端代码文件</th>
                <td>
                    <#texts id="ui" name="ui" value="" placeholder="按钮的前端代码文件路径 例：/order/btn/print.html" style="width:500px;height:20px;" />(必填)
                    <br>
                                        通按钮模版选择:
                    [<a class="template" href="#" title="前端随便写,服务端也是你自己写" data-ui="">自定义</a>]
                    [<a class="template" href="#" title="后台执行逻辑,并刷新前台组件" data-ui="/eova/template/common/btn/execute.html">后台执行</a>]
                    [<a class="template" href="#" title="选中数据,二次确认后,异步提交" data-ui="/eova/template/common/btn/confirm.html">二次确认</a>]
                    [<a class="template" href="#" title="选中数据,输入内容后,异步提交" data-ui="/eova/template/common/btn/input.html">输入内容</a>]
                    [<a class="template" href="#" title="以新窗口方式打开指定URI" data-ui="/eova/template/common/btn/open.html">跳转新窗</a>]
                    [<a class="template" href="#" title="选中数据,同步提交到新窗口" data-ui="/eova/template/common/btn/submit.html">提交新窗</a>]
                    &nbsp;|&nbsp;<a href="http://doc.eova.cn/217082" target="_blank">查看帮助</a>
                    <div id="ui_uri" style="display: none;">
                    	服务端URL<#text id="uri" name="uri" />(谁来处理本按钮的请求)
                    </div>
                </td>
            </tr>
            <tr>
                <th>服务权限配置</th>
                <td>
                    <#texts id="bs" name="bs" placeholder="服务端URI权限配置. 例：\n/order/print;\n/order/print_data;" style="width:500px;height:60px;" /> (必填)
                </td>
            </tr>
            <tr>
                <th>所属按钮组号</th>
                <td>
                    <#text id="group_num" name="group_num" value="0" /> (默认即可,主子模版子表按钮组从1开始)
                </td>
            </tr>
            <tr>
                <th>分配给角色</th>
                <td>
                    <#combo id="role" name="role" exp="selectEovaRole" multiple="true" value="1" /> (可多选)
                </td>
            </tr>
        </table>
</form>

<script type="text/javascript">

    var $form = $('#myForm');

    // js 给下拉框赋值 案例
    // $('#role').eovacombo().setValue(2);

    $(function () {

        $form.validator({
            debug: false,
            stopOnError: true,
            focusInvalid: false,
            showOk: false,
            timely: false,
            msgMaker: false,
            fields: {
                name: {rule: '名称:required;'},
                ui: {rule: '按钮UI路径:required;'},
                bs: {rule: '按钮BS路径:required;'},
            }
        });

        $form.on("validation", function(e, current){
            // 当前字段未验证通过，Tip提示
            if(!current.isValid){
                var tip = $.tipwarn($(current.element).parent(), current.msg);
                //alert(current.msg);
                // 开始输入销毁提示
                $(current.element).keydown(function(event){
                    tip.tooltip('destroy');
                    $(this).unbind("keydown");
                });
            }
        });
        
        $('.template').click(function(){
        	$('#ui').val($(this).data('ui'));
        	var txt = $(this).text();
        	var $uiuri = $('#ui_uri');
        	if(txt == '自定义'){
        		$uiuri.hide();
        		$form.validator("setField", "uri", null);
        	} else {
        		$uiuri.show();
        		$form.validator("setField", "uri", "服务端URL:required;");
        	}
        })
    });

    var btnSaveCallback = function ($dialog, $widget, $pjq) {
        //buildUrl($pjq);
        $form.isValid(function(isValied){
            if(isValied){
                submitNow($dialog, $widget, $pjq);
            }
        });
    };

    var submitNow = function($dialog, $widget, $pjq) {
        var url = "/button/doQuick";
        $.post(url, $.getFormParasObj($form), function (result) {
            if (result.success) {
                $.slideMsg("添加按钮成功！", $pjq);
                $.widgetReLoad($widget);
                $dialog.dialog('destroy');
            } else {
                $pjq.messager.alert('提示', result.msg, 'error');
            }
        }, 'json');
    };
</script>

<%}%>
